/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightTransferFood;
import com.sasis.dao.FlightTransferFoodDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightTransferFoodDaoiBatis extends BaseDaoiBATIS implements FlightTransferFoodDao {

    /**
     * @see com.sasis.dao.FlightTransferFoodDao#getFlightTransferFoods(com.sasis.model.FlightTransferFood)
     */
    public List getFlightTransferFoods(final FlightTransferFood flightTransferFood) {
          return getSqlMapClientTemplate().queryForList("getFlightTransferFoods", flightTransferFood);
    }

    /**
     * @see com.sasis.dao.FlightTransferFoodDao#getFlightTransferFood(Integer id)
     */
    public FlightTransferFood getFlightTransferFood(Integer id) {
        FlightTransferFood flightTransferFood = (FlightTransferFood) getSqlMapClientTemplate().queryForObject("getFlightTransferFood", id);

        //if (flightTransferFood == null) {
            //throw new ObjectRetrievalFailureException(FlightTransferFood.class, id);
        //}

        return flightTransferFood;
    }

    /**
     * @see com.sasis.dao.FlightTransferFoodDao#saveFlightTransferFood(FlightTransferFood flightTransferFood)
     */    
    public int saveFlightTransferFood(final FlightTransferFood flightTransferFood) {
        Integer id = flightTransferFood.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightTransferFood", flightTransferFood);
        } else {
            getSqlMapClientTemplate().update("updateFlightTransferFood", flightTransferFood);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightTransferFood.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightTransferFoodDao#removeFlightTransferFood(Integer id)
     */
    public void removeFlightTransferFood(FlightTransferFood flightTransferFood) {
        getSqlMapClientTemplate().update("deleteFlightTransferFood",  flightTransferFood);
    }
    
    public void deleteFlightTransferFood(FlightTransferFood flightTransferFood){
    	getSqlMapClientTemplate().update("deleteByFlightTransferFoodId",  flightTransferFood);
    	
    }
   
}
